package role;

import com.liCheng.dao.role.RoleMapper;
import com.liCheng.entity.Role;
import com.liCheng.service.role.RoleService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import provider.ProviderTest;

import java.util.ArrayList;
import java.util.List;

public class RoleTest {
    private static Logger logger=Logger.getLogger(RoleTest.class);

    /**
     * 模糊查询
     */
    @Test
    public void roleList(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        RoleService roleService= (RoleService) context.getBean("roleService");
        List<Role> roleList=new ArrayList<Role>();
        Role role=new Role();
        role.setRoleName("员");
        roleList=roleService.roleList(role);
        for (Role role1 : roleList) {
            logger.debug("角色编码："+role1.getRoleCode()
                    +"创建者："+role1.getCreatedBy());
        }
    }

    /**
     * 添加
     */
    @Test
    public void roleAdd(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        RoleService roleService= (RoleService) context.getBean("roleService");
        int count=0;
        Role role=new Role();
        role.setRoleCode("SDW");
        role.setRoleName("你福克斯");
        role.setCreatedBy(2);
        count=roleService.roleAdd(role);
        if(count>0){
            logger.debug("添加成功");
        }
    }

    /**
     * 修改
     */
    @Test
    public void roleUpdate(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        RoleService roleService= (RoleService) context.getBean("roleService");
        int count=0;
        Role role=new Role();
        role.setId(5);
        role.setRoleCode("abc");
        role.setRoleName("福克斯");
        count=roleService.roleUpdate(role);
        if(count>0){
            logger.debug("修改成功");
        }
    }

    /**
     * 删除
     */
    @Test
    public void roleDel(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        RoleService roleService= (RoleService) context.getBean("roleService");
        int count=0;
        Role role=new Role();
        role.setId(6);
        count=roleService.roleDel(role);
        if(count>0){
            logger.debug("删除成功");
        }
    }
}
